package com.example.foobar.dao.service.impl;

import com.example.foobar.business.service.ImsAccountWechatsService;
import com.example.foobar.dao.service.ImsAccountWechatsDaoService;
import com.example.foobar.entity.DaOfficialAccount;
import com.example.foobar.entity.ImsAccountWechats;
import com.example.foobar.mapper.DaOfficialAccountMapper;
import com.example.foobar.dao.service.DaOfficialAccountDaoService;
import com.example.foobar.param.DaOfficialAccountPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 本地公众号信息 服务实现类
 *
 * @author 郑英奔
 * @since 2021-05-31
 */
@Slf4j
@Service
public class DaOfficialAccountDaoServiceImpl extends BaseServiceImpl<DaOfficialAccountMapper, DaOfficialAccount> implements DaOfficialAccountDaoService {

    @Autowired
    private DaOfficialAccountMapper daOfficialAccountMapper;

    @Autowired
    private ImsAccountWechatsService imsAccountWechatsService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDaOfficialAccount(DaOfficialAccount daOfficialAccount) throws Exception {
        return super.save(daOfficialAccount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDaOfficialAccount(DaOfficialAccount daOfficialAccount) throws Exception {
        return super.updateById(daOfficialAccount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDaOfficialAccount(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<DaOfficialAccount> getDaOfficialAccountPageList(DaOfficialAccountPageParam daOfficialAccountPageParam) throws Exception {
        Page<DaOfficialAccount> page = new PageInfo<>(daOfficialAccountPageParam, OrderItem.desc(getLambdaColumn(DaOfficialAccount::getCreateTime)));
        LambdaQueryWrapper<DaOfficialAccount> wrapper = new LambdaQueryWrapper<>();
        IPage<DaOfficialAccount> iPage = daOfficialAccountMapper.selectPage(page, wrapper);
        return new Paging<DaOfficialAccount>(iPage);
    }

    @Override
    public int delete(LambdaQueryWrapper<DaOfficialAccount> daOfficialAccountLambdaQueryWrapper) {
        return daOfficialAccountMapper.delete(daOfficialAccountLambdaQueryWrapper);
    }

    @Override
    public void insertBatch(List<DaOfficialAccount> collect) {
        daOfficialAccountMapper.insertBatch(collect);
    }

    @Override
    public DaOfficialAccount selectOne(LambdaQueryWrapper<DaOfficialAccount> wrapper) {

        return daOfficialAccountMapper.selectOne(wrapper);
    }

    @Override
    public List<DaOfficialAccount> getDaOfficialAccountListByUserId(Long userId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        return daOfficialAccountMapper.getDaOfficialAccountListByUserId(params);
    }

}
